package com.nsgf.library.ui.page.manager;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.kunminx.architecture.ui.page.DataBindingConfig;
import com.kunminx.architecture.ui.state.State;
import com.nsgf.library.BR;
import com.nsgf.library.R;
import com.nsgf.library.data.bean.UserInfo;
import com.nsgf.library.data.bean.WorkOrderDetailBean;
import com.nsgf.library.databinding.FragmentNagfWorkAlreadyOrderRecordBinding;
import com.nsgf.library.domain.request.AccountRequester;
import com.nsgf.library.photopicker.widget.MultiPickResultView;
import com.nsgf.library.ui.adapter.ManagerDamListAdapter;
import com.nsgf.library.ui.adapter.ManagerDamTaskRecordListAdapter;
import com.nsgf.library.ui.page.BaseFragment;
import com.nsgf.library.ui.page.StateHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * 工单已办巡查记录
 */
public class WorkOrderExamineAlreadyRecordFragment extends BaseFragment {

    public static WorkOrderExamineAlreadyRecordFragment newInstance(WorkOrderDetailBean.DataBean dataBean) {
        WorkOrderExamineAlreadyRecordFragment messageFragment = new WorkOrderExamineAlreadyRecordFragment();
        Bundle bundle = new Bundle();
        bundle.putParcelable("dataBean", dataBean);
        messageFragment.setArguments(bundle);
        return messageFragment;

    }

    private WorkOrderDetailBean.DataBean getDataBean() {
        return getArguments().getParcelable("dataBean");
    }

    private WorkOrderAlreadyRecordFragmentStates mStates;

    FragmentNagfWorkAlreadyOrderRecordBinding mBinding;

    @Override
    protected void initViewModel() {
        mStates = getActivityScopeViewModel(WorkOrderAlreadyRecordFragmentStates.class);
        mAccountRequester = getActivityScopeViewModel(AccountRequester.class);

    }

    private AccountRequester mAccountRequester;

    private ManagerDamListAdapter mAdapter;
    private ManagerDamTaskRecordListAdapter mAdapterItem;

    @Override
    protected DataBindingConfig getDataBindingConfig() {

        mAdapter = new ManagerDamListAdapter(getContext(), 2);
        mAdapterItem = new ManagerDamTaskRecordListAdapter(getContext());

        return new DataBindingConfig(R.layout.fragment_nagf_work_already_order_record, BR.vm, mStates)
                .addBindingParam(BR.adapterItem, mAdapterItem)
                .addBindingParam(BR.adapter, mAdapter);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        getLifecycle().addObserver(mAccountRequester);
        mBinding = (FragmentNagfWorkAlreadyOrderRecordBinding) getBinding();

        mStates.list.set(getDataBean().getPositionVOS());
        mAdapter.notifyDataSetChanged();

        mBinding.multiPickResultView.init(getActivity(), MultiPickResultView.ACTION_ONLY_SHOW, (ArrayList<WorkOrderDetailBean.FileDto>) getDataBean().getPhotos(), 3);
        mStates.detailBeanState.set(getDataBean());

    }

    public static class WorkOrderAlreadyRecordFragmentStates extends StateHolder {

        public final State<String> name = new State<>(UserInfo.getInstance().getProjectName());
        public final State<String> appLog = new State<>(UserInfo.getInstance().getAppLog());

        public final State<List<WorkOrderDetailBean.DataBean.PositionVOSBean>> list = new State<>(new ArrayList<>());

        public final State<WorkOrderDetailBean.DataBean> detailBeanState = new State<WorkOrderDetailBean.DataBean>(null);

        public final State<WorkOrderDetailBean.DataBean.PositionVOSBean> data = new State<>(null);
        public final State<List<WorkOrderDetailBean.DataBean.PositionVOSBean.ItemsBean>> dataItem = new State<>(null);

        public final State<Boolean> loadingVisible = new State<>(false);
        public final State<String> distance = new State<>("");

    }

    /**
     * 当前页数
     */
    private int index = 0;

}
